/**
 * PanelReporteNotasHogar.java
 */

 /**
 *  AdSec: Administrador de Secundarias
 *  Copyright (C) 2009 Daniela Ramírez Chaves (dannyrch@gmail.com)
 *  Copyright (C) 2009 Leonel Salazar Valverde (leo87sv@gmail.com)
 *
 *  This file is part of AdSec.
 *  AdSec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AdSec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AdSec.  If not, see <http://www.gnu.org/licenses/>.
 */

package adsec.presentacion;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import adsec.entidades.Anio;
import adsec.entidades.Estado;
import adsec.entidades.Estudiante;
import adsec.entidades.Materia;
import adsec.entidades.Permiso;
import adsec.entidades.entidadesReportes.MatrizReportesNotas;
import adsec.entidades.entidadesReportes.ReporteMateriaAplazada;
import adsec.negocios.AdministradorSeguridad;
import adsec.negocios.ControladoraReportes;
import adsec.negocios.ImpresorHTML;
import adsec.negocios.UtilidadesCapaNegocios;
import adsec.presentacion.UtilidadesPresentacion.HtmlFilter;
import org.jdesktop.application.Action;


public class PanelReporteNotasHogar extends javax.swing.JPanel implements ActionListener{

    private ControladoraReportes contReportes;
    private AdministradorSeguridad adminSeguridad;
    private Permiso permisoResponsable;
    private Estado estado;
    private ImpresorHTML impresorHTML;
    
    /** Creates new form PanelReporteNotasHogar */
    public PanelReporteNotasHogar() {
        initComponents();
    }

    public void iniciarPanelReporteNotasHogar(){
        this.contReportes = new ControladoraReportes();
        this.adminSeguridad = AdministradorSeguridad.getInstancia();
        this.permisoResponsable = this.adminSeguridad.getPermiso(UtilidadesCapaNegocios.moduloReportes);
        this.estado = new Estado();
        this.cargarComboBoxAños();
        this.cargarComboBoxDatosEstudiante();
        this.impresorHTML = new ImpresorHTML();
        //this.impresorHTML.setFileName("temp.html");
    }

    /********************************************
     * CARGAR DATOS
     ********************************************/
    private void cargarComboBoxAños(){
        LinkedList<Anio> listaAños = this.contReportes.consultarAnios();
        Iterator<Anio> iterador = listaAños.iterator();
        this.cbAnio.addItem(new String(""));
        while(iterador.hasNext()){
            this.cbAnio.addItem(Integer.toString(iterador.next().getAnio()));
        }
    }

    private void cargarComboBoxDatosEstudiante(){
        LinkedList<Estudiante> listaEstudiantes = contReportes.consultarEstudiantes();
        DefaultComboBoxModel modeloCedula = new DefaultComboBoxModel();
        DefaultComboBoxModel modeloNombreApellidos = new DefaultComboBoxModel();
        modeloCedula.addElement("");
        modeloNombreApellidos.addElement("");
        Iterator<Estudiante> iterador = listaEstudiantes.iterator();
        while(iterador.hasNext()){
            Estudiante estudiante = iterador.next();
            modeloCedula.addElement(estudiante.getCedula());
            modeloNombreApellidos.addElement(estudiante.getNombre() + " " + estudiante.getApellidos());
        }//fin de while
        this.cbCedula.setModel(modeloCedula);
        this.cbNombreApellidos.setModel(modeloNombreApellidos);
    }//fin de cargarComboBoxDatosEstudiante

    private int cargarGridNotasMaterias(int tipoMateria){
        int cantidadPeriodos = 0;
        if(cbAnio.getSelectedIndex() > 0 && cbCedula.getSelectedIndex() > 0){
            int anio = Integer.parseInt(cbAnio.getSelectedItem().toString());
            String cedula = cbCedula.getSelectedItem().toString();
            MatrizReportesNotas reportes = this.contReportes.consultarReporteNotas(anio, cedula, tipoMateria);
            if(reportes != null && reportes.cantidadReportes() > 0){
                cantidadPeriodos = reportes.getCantPeriodos();
                String[] headers = reportes.getHeader();
                for(int i = 0; i < headers.length; i++){
                    this.agregarColumna(headers[i], tipoMateria);
                }
                this.impresorHTML.agregarHeaderNotas(headers, tipoMateria);
                for(int i = 0; i < reportes.cantidadReportes(); i++){
                    String[] reporte = reportes.getReporte(i);
                    this.agregarReporte(reporte, tipoMateria);
                    this.impresorHTML.agregarFilaNotas(reporte, tipoMateria);
                }
                
            }
        }
        return cantidadPeriodos;
    }

    private void cargarGridMateriasAplazadas(){
        if(cbAnio.getSelectedIndex() > 0 && cbCedula.getSelectedIndex() > 0){
            int anio = Integer.parseInt(cbAnio.getSelectedItem().toString());
            String cedula = cbCedula.getSelectedItem().toString();
            LinkedList<ReporteMateriaAplazada> reportes = this.contReportes.consultarMateriasAplazadas(anio, cedula);
            Iterator<ReporteMateriaAplazada> iterador = reportes.iterator();
            while(iterador.hasNext()){
                ReporteMateriaAplazada rep = iterador.next();
                Object[] reporte = new Object[7];
                String [] notasAplazados = new String[reporte.length];
                reporte[0] = rep.getNivel();
                reporte[1] = rep.getNum_seccion();
                reporte[2] = rep.getNombreMateria();
                reporte[3] = rep.getNotaConv1();
                reporte[4] = rep.getEstado_conv1();
                reporte[5] = rep.getNotaConv2();
                reporte[6] = rep.getEstado_conv2();
                ((DefaultTableModel)this.gridMateriasAplazadas.getModel()).addRow(reporte);
                for(int i = 0; i < notasAplazados.length; i++){
                    notasAplazados[i] = reporte[i] != null ? reporte[i].toString() : "";
                }
                this.impresorHTML.agregarFilaAplazados(notasAplazados);
            }
        }
    }

    private void cargarGridAsistenciaPeriodo(int cantidadPeriodos){
        if(cbAnio.getSelectedIndex() > 0 && cbCedula.getSelectedIndex() > 0){
            int anio = Integer.parseInt(cbAnio.getSelectedItem().toString());
            String cedula = cbCedula.getSelectedItem().toString();
            String[][] reportes = contReportes.consultarAsistenciaPeriodo(anio, cedula, cantidadPeriodos);
            for(int i = 0; i< reportes[0].length; i++){
                ((DefaultTableModel)this.gridAsistencia.getModel()).addColumn(reportes[0][i]);
            }
            this.impresorHTML.agregarHeaderAsistencia(reportes[0]);
            
            for(int i = 1; i < reportes.length; i++){
               ((DefaultTableModel)this.gridAsistencia.getModel()).addRow(reportes[i]);
               this.impresorHTML.agregarFilaAsistencia(reportes[i]);
            }
        }
    }

     /********************************************
     * MODIFICACION GRID
     ********************************************/
    private void agregarColumna(Object columnaAgregar, int tipoMateria) {
        switch(tipoMateria){
            case Materia.NORMAL:
                ((DefaultTableModel)this.gridNotasNormales.getModel()).addColumn(columnaAgregar);
                break;
            case Materia.TECNOLOGIA:
                ((DefaultTableModel)this.gridNotasTecnologia.getModel()).addColumn(columnaAgregar);
                break;
            case Materia.ESPECIAL:
                ((DefaultTableModel)this.gridNotasEspeciales.getModel()).addColumn(columnaAgregar);
                break;
        }
    }

    private void agregarReporte(String [] reporte, int tipoMateria){
        Object [] arrayObjects = new Object[reporte.length];
        for(int i = 0; i < reporte.length; i++){
            arrayObjects[i] = (Object) reporte[i];
        }
        switch(tipoMateria){
            case Materia.NORMAL:
                ((DefaultTableModel)this.gridNotasNormales.getModel()).addRow(arrayObjects);
                break;
            case Materia.TECNOLOGIA:
                ((DefaultTableModel)this.gridNotasTecnologia.getModel()).addRow(arrayObjects);
                break;
            case Materia.ESPECIAL:
                ((DefaultTableModel)this.gridNotasEspeciales.getModel()).addRow(arrayObjects);
                break;
        }
    }

    /*private void quitarColumna(Object columnaQuitar, int tipoMateria) {
        int i = this.gridNotasNormales.getColumnCount();
        this.gridNotasNormales.getColumnModel().removeColumn(gridNotasNormales.getColumn(columnaQuitar));
    }*/

   /********************************************
    * EVENTOS
    ********************************************/
    public void actionPerformed(ActionEvent evento){
        JComboBox fuente = (JComboBox) evento.getSource();
        if(fuente == this.cbCedula){
            this.cbNombreApellidos.removeActionListener(this);
            this.cbNombreApellidos.setSelectedIndex(this.cbCedula.getSelectedIndex());
            this.cbNombreApellidos.addActionListener(this);
        }else{
            if(fuente == this.cbNombreApellidos){
                this.cbCedula.removeActionListener(this);
                this.cbCedula.setSelectedIndex(this.cbNombreApellidos.getSelectedIndex());
                this.cbCedula.addActionListener(this);
            }    
        }
        this.verificarCargarNivel();
        this.verificarCargarGrid();
    }

    private void verificarCargarGrid(){
        if(cbAnio.getSelectedIndex() > 0 && this.cbCedula.getSelectedIndex() > 0
                && this.cbNombreApellidos.getSelectedIndex() > 0){
            this.limpiarGrids();
            this.impresorHTML.limpiarDatos();
            this.impresorHTML.agregarDatosEstudiante((String)cbCedula.getSelectedItem(),
                    (String)cbNombreApellidos.getSelectedItem(), this.txtNivel.getText());
            int cantidadMayor = this.cargarGridNotasMaterias(Materia.NORMAL);
            int cantidad = this.cargarGridNotasMaterias(Materia.TECNOLOGIA);
            if(cantidadMayor < cantidad){
                cantidadMayor = cantidad;
            }
            cantidad = this.cargarGridNotasMaterias(Materia.ESPECIAL);
            if(cantidadMayor < cantidad){
                cantidadMayor = cantidad;
            }
            this.cargarGridAsistenciaPeriodo(cantidadMayor);
            this.cargarGridMateriasAplazadas();
            this.btnExportarHTML.setEnabled(true);
            //System.out.println(this.impresorHTML.imprimirHTML());
        }else{
            this.limpiarGrids();
            this.btnExportarHTML.setEnabled(false);
        }
    }//fin de itemStateChanged

    private void verificarCargarNivel(){
        if(cbAnio.getSelectedIndex() > 0 && this.cbCedula.getSelectedIndex() > 0
                && this.cbNombreApellidos.getSelectedIndex() > 0){
            int anio = Integer.parseInt(cbAnio.getSelectedItem().toString());
            String cedula = cbCedula.getSelectedItem().toString();
            int nivel =  this.contReportes.consultarNivelActualEstudiante(anio, cedula);
            this.txtNivel.setText(Integer.toString(nivel));
        }else{
            this.txtNivel.setText("");
        }
    }

    private void limpiarGrids(){
        ((DefaultTableModel)this.gridNotasNormales.getModel()).setRowCount(0);
        ((DefaultTableModel)this.gridNotasNormales.getModel()).setColumnCount(0);
        ((DefaultTableModel)this.gridMateriasAplazadas.getModel()).setRowCount(0);
        ((DefaultTableModel)this.gridAsistencia.getModel()).setRowCount(0);
        ((DefaultTableModel)this.gridAsistencia.getModel()).setColumnCount(0);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbAnio = new javax.swing.JLabel();
        cbAnio = new javax.swing.JComboBox();
        lbEstudiante = new javax.swing.JLabel();
        cbCedula = new javax.swing.JComboBox();
        cbNombreApellidos = new javax.swing.JComboBox();
        scrollGridNotasNormales = new javax.swing.JScrollPane();
        gridNotasNormales = new javax.swing.JTable();
        lbNotasMateria = new javax.swing.JLabel();
        scrollAsistencia = new javax.swing.JScrollPane();
        gridAsistencia = new javax.swing.JTable();
        lbAsistencia = new javax.swing.JLabel();
        lbMateriasAplazadas = new javax.swing.JLabel();
        scrollMateriasAplazadas = new javax.swing.JScrollPane();
        gridMateriasAplazadas = new javax.swing.JTable();
        lbTecnologia = new javax.swing.JLabel();
        scrollNotasTecno = new javax.swing.JScrollPane();
        gridNotasTecnologia = new javax.swing.JTable();
        lbEspeciales = new javax.swing.JLabel();
        scrollNotasEspeciales = new javax.swing.JScrollPane();
        gridNotasEspeciales = new javax.swing.JTable();
        lbNivel = new javax.swing.JLabel();
        txtNivel = new javax.swing.JTextField();
        btnExportarHTML = new javax.swing.JButton();

        setMaximumSize(new java.awt.Dimension(700, 970));
        setMinimumSize(new java.awt.Dimension(700, 970));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(700, 970));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(adsec.presentacion.LiceoEscazuApp.class).getContext().getResourceMap(PanelReporteNotasHogar.class);
        lbAnio.setText(resourceMap.getString("lbAnio.text")); // NOI18N
        lbAnio.setName("lbAnio"); // NOI18N

        cbAnio.setName("cbAnio"); // NOI18N

        lbEstudiante.setText(resourceMap.getString("lbEstudiante.text")); // NOI18N
        lbEstudiante.setName("lbEstudiante"); // NOI18N

        cbCedula.setName("cbCedula"); // NOI18N

        cbNombreApellidos.setName("cbNombreApellidos"); // NOI18N

        scrollGridNotasNormales.setName("scrollGridNotasNormales"); // NOI18N

        gridNotasNormales.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        gridNotasNormales.setName("gridNotasNormales"); // NOI18N
        scrollGridNotasNormales.setViewportView(gridNotasNormales);

        lbNotasMateria.setText(resourceMap.getString("lbNotasMateria.text")); // NOI18N
        lbNotasMateria.setName("lbNotasMateria"); // NOI18N

        scrollAsistencia.setName("scrollAsistencia"); // NOI18N

        gridAsistencia.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        gridAsistencia.setName("gridAsistencia"); // NOI18N
        scrollAsistencia.setViewportView(gridAsistencia);

        lbAsistencia.setText(resourceMap.getString("lbAsistencia.text")); // NOI18N
        lbAsistencia.setName("lbAsistencia"); // NOI18N

        lbMateriasAplazadas.setText(resourceMap.getString("lbMateriasAplazadas.text")); // NOI18N
        lbMateriasAplazadas.setName("lbMateriasAplazadas"); // NOI18N

        scrollMateriasAplazadas.setName("scrollMateriasAplazadas"); // NOI18N

        gridMateriasAplazadas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nivel", "Sección", "Materia", "Nota Conv. 1", "Estado", "Nota Conv. 2", "Estado"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gridMateriasAplazadas.setName("gridMateriasAplazadas"); // NOI18N
        scrollMateriasAplazadas.setViewportView(gridMateriasAplazadas);

        lbTecnologia.setText(resourceMap.getString("lbTecnologia.text")); // NOI18N
        lbTecnologia.setName("lbTecnologia"); // NOI18N

        scrollNotasTecno.setName("scrollNotasTecno"); // NOI18N

        gridNotasTecnologia.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        gridNotasTecnologia.setName("gridNotasTecnologia"); // NOI18N
        scrollNotasTecno.setViewportView(gridNotasTecnologia);

        lbEspeciales.setText(resourceMap.getString("lbEspeciales.text")); // NOI18N
        lbEspeciales.setName("lbEspeciales"); // NOI18N

        scrollNotasEspeciales.setName("scrollNotasEspeciales"); // NOI18N

        gridNotasEspeciales.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        gridNotasEspeciales.setName("gridNotasEspeciales"); // NOI18N
        scrollNotasEspeciales.setViewportView(gridNotasEspeciales);

        lbNivel.setText(resourceMap.getString("lbNivel.text")); // NOI18N
        lbNivel.setName("lbNivel"); // NOI18N

        txtNivel.setEditable(false);
        txtNivel.setText(resourceMap.getString("txtNivel.text")); // NOI18N
        txtNivel.setName("txtNivel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(adsec.presentacion.LiceoEscazuApp.class).getContext().getActionMap(PanelReporteNotasHogar.class, this);
        btnExportarHTML.setAction(actionMap.get("exportarHtml")); // NOI18N
        btnExportarHTML.setText(resourceMap.getString("btnExportarHTML.text")); // NOI18N
        btnExportarHTML.setName("btnExportarHTML"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(scrollMateriasAplazadas, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
                            .addComponent(scrollNotasTecno, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
                            .addComponent(scrollGridNotasNormales, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
                            .addComponent(lbEspeciales)
                            .addComponent(lbMateriasAplazadas)
                            .addComponent(lbNotasMateria)
                            .addComponent(lbTecnologia)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbAsistencia)
                            .addComponent(scrollNotasEspeciales, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(scrollAsistencia, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbEstudiante)
                            .addComponent(lbAnio)
                            .addComponent(lbNivel))
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbAnio, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbNombreApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtNivel, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(565, Short.MAX_VALUE)
                        .addComponent(btnExportarHTML)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbAnio)
                    .addComponent(cbAnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbEstudiante)
                    .addComponent(cbCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbNombreApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbNivel)
                    .addComponent(txtNivel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbNotasMateria)
                .addGap(5, 5, 5)
                .addComponent(scrollGridNotasNormales, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbTecnologia)
                .addGap(12, 12, 12)
                .addComponent(scrollNotasTecno, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbEspeciales)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(scrollNotasEspeciales, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbAsistencia)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(scrollAsistencia, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(lbMateriasAplazadas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(scrollMateriasAplazadas, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExportarHTML)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        cbAnio.addActionListener(this);
        cbCedula.addActionListener(this);
        cbNombreApellidos.addActionListener(this);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void exportarHtml() {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
        fileChooser.setFileFilter(new HtmlFilter("Archivo Html(*.html)", new String[]{"html"}));
        if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){
            File archivo = fileChooser.getSelectedFile();
            if(archivo != null){
                try{
                    String directorio = archivo.getCanonicalPath();
                    String nombreArchivo = directorio + ".html";
                    this.impresorHTML.setFileName(nombreArchivo);
                    this.impresorHTML.imprimirHTML();
                }catch(IOException e){
                    JOptionPane.showMessageDialog(this, "Error al guardar el archivo", "Error", JOptionPane.ERROR_MESSAGE);
                }
            }else{
                JOptionPane.showMessageDialog(this, "Error al guardar el archivo", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExportarHTML;
    private javax.swing.JComboBox cbAnio;
    private javax.swing.JComboBox cbCedula;
    private javax.swing.JComboBox cbNombreApellidos;
    private javax.swing.JTable gridAsistencia;
    private javax.swing.JTable gridMateriasAplazadas;
    private javax.swing.JTable gridNotasEspeciales;
    private javax.swing.JTable gridNotasNormales;
    private javax.swing.JTable gridNotasTecnologia;
    private javax.swing.JLabel lbAnio;
    private javax.swing.JLabel lbAsistencia;
    private javax.swing.JLabel lbEspeciales;
    private javax.swing.JLabel lbEstudiante;
    private javax.swing.JLabel lbMateriasAplazadas;
    private javax.swing.JLabel lbNivel;
    private javax.swing.JLabel lbNotasMateria;
    private javax.swing.JLabel lbTecnologia;
    private javax.swing.JScrollPane scrollAsistencia;
    private javax.swing.JScrollPane scrollGridNotasNormales;
    private javax.swing.JScrollPane scrollMateriasAplazadas;
    private javax.swing.JScrollPane scrollNotasEspeciales;
    private javax.swing.JScrollPane scrollNotasTecno;
    private javax.swing.JTextField txtNivel;
    // End of variables declaration//GEN-END:variables

}
